<template>
  <div class="add">
  
    <el-breadcrumb separator-class="el-icon-arrow-right">
  <el-breadcrumb-item :to="{ path: '/about' }">首页</el-breadcrumb-item>
  <el-breadcrumb-item>商品管理</el-breadcrumb-item>
  <el-breadcrumb-item>添加商品</el-breadcrumb-item>
    </el-breadcrumb>

<el-card>
  <el-alert
    title="注意:添加商品信息"
     type="warning"
     center
     show-icon
     :closable="false" 
     >
  </el-alert>

 <el-steps :space="200" :active="act-0" finish-status="success" align-center>
  <el-step title="基本信息"></el-step>
  <el-step title="商品参数"></el-step>
  <el-step title="商品属性"></el-step>
  <el-step title="商品图片"></el-step>
  <el-step title="商品内容"></el-step>
  <el-step title="完成"></el-step>
   
</el-steps>
<el-form :model="addForm" label-width="100px" label-position="top" >
<el-tabs :tab-position="'left'" v-model="act" :before-leave="befo" @tab-click="cli">
    <el-tab-pane label="基本信息" name="0">
         <el-form-item label="商品名称" >
            <el-input v-model="addForm.goods_name"></el-input>
         </el-form-item>
          <el-form-item label="商品价格" >
            <el-input v-model="addForm.goods_price"></el-input>
         </el-form-item>
          <el-form-item label="商品重量" >
            <el-input v-model="addForm.goods_weight"></el-input>
         </el-form-item>
          <el-form-item label="商品数量" >
            <el-input v-model="addForm.goods_number"></el-input>
         </el-form-item>
           <el-form-item label="商品分类" >
           <el-cascader
            clearable
             v-model="addForm.goods_cat"
            :options="list"
            :props="pos"
             @change="handleChange"></el-cascader>
         </el-form-item>
         
    </el-tab-pane>
    <el-tab-pane label="商品参数" name="1">
         <el-form-item :label="obj.cat_name" >
            
         </el-form-item>
    </el-tab-pane>
    <el-tab-pane label="商品属性" name="2"> </el-tab-pane>
    <el-tab-pane label="商品图片" name="3">
        <el-upload
        :headers="headobj"
          action="upload"
          :on-preview="handlePreview"
           :on-remove="handleRemove"
           list-type="picture">
         <el-button size="small" type="primary">点击上传</el-button>
         <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
       </el-upload>
    </el-tab-pane>
    <el-tab-pane label="商品内容" name="4">
      <!-- 文本编辑器 -->
         <quill-editor v-model="addForm.goods_introduce"
               >
        </quill-editor>
    </el-tab-pane>
  </el-tabs>
  </el-form>

</el-card>

  </div>
</template>
<script>

  
export default {

  data() {
    return{
    
      act:0,
       addForm:{
          goods_name :'',
          goods_cat  :[],
          goods_price   :'',
          goods_number   :'',
          goods_weight   :'',
          goods_introduce:'',
          pics :'',
          attrs :'',    
        },
        upload:'https://lianghj.top:8888/api/private/v1/upload',
        list:[],
        headobj:{
             Authorization:window.sessionStorage.getItem('token')
        },
        obj:{},
        pos:{
          label:'cat_name',
          value:'cat_id',
          children:'children'
        }
    
    
    }
  },
  components:{
   
  },
  created(){
    this.getlist()
  },
  methods:{
    async getlist(){
       const {data:res}=await this.$http.get('categories')
       
       this.list=res.data
    },

    handleChange(val){
     
    },
    befo(qu,zai){
  if (zai==='0'&&this.addForm.goods_cat.length!==3) {
     this.$message.error("没有选择商品");
     return false
  }

    },
    // tab被点击时触发
   async cli(){
      console.log();
      if (this.act==1) {
       const {data:res}=await this.$http.get(`categories/${this.addForm.goods_cat[2]}`,{params:{sel:'many'}})
       console.log(res.data);
       this.obj=res.data
      }
    },
    // 上传图片预览
    handlePreview(){

    },
    // 删除图片操作
    handleRemove(){

    }
   
  }
}
</script>


<style lang="less" scoped>
.el-card{
  margin-top: 30px;
 line-height: 20px; 

}
/deep/.el-alert{
  background-color: rgb(206, 204, 204);
  
  color: #000;
   
}
.el-steps{
 margin-top: 40px;
}

/deep/.el-step__title{
  font-size: 14px;
}
.el-tabs {
 margin-top: 50px;
}

</style>
